import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import { useAppSelector } from '../store';

// 导入屏幕组件
import AuthNavigator from './AuthNavigator';
import MainNavigator from './MainNavigator';
import LoadingScreen from '../screens/LoadingScreen';
import CarListScreen from '../zzy/CarListScreen';
import CarDetailScreen from '../zzy/CarDetailScreen';

export type RootStackParamList = {
  Auth: undefined;
  Main: undefined;
  Loading: undefined;
  CarList: undefined;
  CarDetail: {
    carId: string;
  };
};

const Stack = createStackNavigator<RootStackParamList>();

const RootNavigator: React.FC = () => {
  const { isAuthenticated, isLoading } = useAppSelector((state) => state.auth);

  if (isLoading) {
    return <LoadingScreen />;
  }

  return (
    <Stack.Navigator 
      screenOptions={{ 
        headerShown: false,
        // 禁用 react-native-screens
        animationEnabled: true,
        gestureEnabled: true,
      }}
    >
      {isAuthenticated ? (
        <>
          <Stack.Screen name="Main" component={MainNavigator} />
          <Stack.Screen
            name="CarList"
            component={CarListScreen}
            options={{ headerShown: true, title: '车辆列表' }}
          />
          <Stack.Screen
            name="CarDetail"
            component={CarDetailScreen}
            options={{ headerShown: true, title: '车辆详情' }}
          />
        </>
      ) : (
        <Stack.Screen name="Auth" component={AuthNavigator} />
      )}
    </Stack.Navigator>
  );
};

export default RootNavigator; 